package com.aditya.videoutil;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

public class VideoActivity extends Activity {

	protected File mainFile = null;
	protected String errorMessage = "";

	protected void setInvisible(int... ids) {
		for (int id : ids) {
			findViewById(id).setVisibility(View.GONE);
		}

	}

	protected void setVisible(int... ids) {
		for (int id : ids) {
			findViewById(id).setVisibility(View.VISIBLE);
		}

	}

	protected void showCannotReadFileDialog(File file) {
		getAlertDialog().setTitle("Invalid selection")
				.setMessage("[" + file.getName() + "] folder can't be read!")
				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				}).show();

	}

	protected void showCancelledMsg() {
		Toast.makeText(this, "Operation cancelled", Toast.LENGTH_SHORT).show();
	}

	public android.app.AlertDialog.Builder getAlertDialog() {
		return new AlertDialog.Builder(this);
	}

	protected void hideButtons() {
		LinearLayout open_button = (LinearLayout) findViewById(R.id.openPDF);
		LinearLayout share_button = (LinearLayout) findViewById(R.id.sharePDF);

		LinearLayout delete_button = (LinearLayout) findViewById(R.id.deletePDF);
		LinearLayout rename_button = (LinearLayout) findViewById(R.id.renamePDF);
		open_button.setVisibility(View.GONE);
		share_button.setVisibility(View.GONE);
		delete_button.setVisibility(View.GONE);

		rename_button.setVisibility(View.GONE);
	}

	protected Builder getSimpleAlertDialog(String title, String msg) {
		return getAlertDialog().setTitle(title).setMessage(msg)
				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_video);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.video, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Take appropriate action for each action item click
		switch (item.getItemId()) {

		// case R.id.action_search:
		// // search action
		// return true;
		//
		// case R.id.action_refresh:
		// // refresh
		// return true;
		// case R.id.action_help:
		// startActivity(new Intent(this, AboutActivity.class));
		// return true;
		// case R.id.action_check_updates:
		// // check for updates action
		// return true;

		case R.id.my_videos:
			startActivity(new Intent(this, MyVideosActivity.class));
			return true;
			
		case R.id.about:
			startActivity(new Intent(this, AboutActivity.class));
			return true;

		case R.id.home:
			Intent intent = new Intent(this, VideoUtilHomeActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			return true;

		default:
			return super.onOptionsItemSelected(item);

		}

	}

}
